import {
  Get,
  Post,
  JsonPost
} from "../../utils/request.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    infoData: {},
    numInfo: {},
    wpxIos:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      wpxIos: getApp().globalData.wpxIos
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#ffffff'
    })
  },
  // 获取用户信息
  bindGetUserInfo(e) {
    getApp().ttClogin()
    getApp().userInfoReadyCallback = () => {
      this.getInfo()
      this.getNum()
    }
  },

  goAccoutSet(){
    wx.navigateTo({
      url: '/pages/accountSet/accountSet',
    })
  },

  myOrder(e){
    wx.navigateTo({
      url: '/pages/myOder/myOder?type='+e.currentTarget.dataset.type,
    })
  },

  mySale(){
    wx.navigateTo({
      url: '/pages/saleList/saleList',
    })
  },

    
  goWeb(e){
    wx.navigateTo({
      url: '/pages/webView/webView?url='+e.currentTarget.dataset.url+'&title=关于淘陶仓',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  getInfo(){
    JsonPost('user/info').then(res=>{
      this.setData({
        infoData:res.data
      })
    })
  },

  // 获取订单数量
  getNum(){
    JsonPost('order/statistics').then(res=>{
      this.setData({
        numInfo:res.data
      })
    })
  },

  goPage(e){
    console.log(e.currentTarget.dataset.page);
    if (e.currentTarget.dataset.page=='shopCart') {
      wx.switchTab({
        url: '/pages/shopCart/shopCart'
      })
      return
    }
    let url=e.currentTarget.dataset.page
    let imgUrl=e.currentTarget.dataset.url
    if (imgUrl) {
      wx.navigateTo({
        url: '/pages/'+url+'/'+url+"?imgUrl="+imgUrl,
      })
    }else{
      wx.navigateTo({
        url: '/pages/'+url+'/'+url,
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4
      })
    }
    if (wx.getStorageSync('token') && (new Date().getTime() - wx.getStorageSync('loginTime') < 604800000)) {
      this.getInfo()
      this.getNum()
    }
  },

    //前往扫码页
    goSaoMa() {
      wx.scanCode({　
        success: (res) => {　　
         console.log(res);
         let id=decodeURIComponent(res.result).split("?goods_id=")[1]
         wx.navigateTo({
           url: '/pages/goodsDetail/goodsDetail?goods_id='+id,
         })
        }　
    })
    },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})